import time

from numpy import *
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import cross_val_score
from data import loadDataFromMat
def runAdaBoost(dataName='banana'):
    data=loadDataFromMat(dataName)
    X = data[0]
    y = ravel(data[1])
    num=y.shape[0]
    trainnum=num//10*8
    start = time.clock()
    clf = AdaBoostClassifier(n_estimators=10)  # 指定10个弱分类器
    clf.fit(X[:trainnum], y[:trainnum])
    s = clf.score(X, y)
    # print((1 - s) * 100)
    end = time.clock()
    return end - start, (1 - s) * 100
    # label = array(y)
    # scores = cross_val_score(clf, mat(X), label)  # 模型 数据集 目标变量
    # print(scores.mean())
# print('AdaBoost',end=',')
# for dataname in ['banana', 'breast_cancer', 'diabetis', 'flare_solar', 'german', 'heart', 'image', 'ringnorm', 'splice', 'thyroid',
#      'titanic', 'twonorm', 'waveform']:
#     runAdaBoost(dataname)
# runAdaBoost()
